﻿using Microsoft.Win32;
using SuporeSliplampApp.Models;
using SuporeSliplampApp.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using static SuporeSliplampApp.Models.PicInputModel;
using static SuporeSliplampApp.Models.CameraModel;
using SuporeSliplampApp.Control;
using SuporeSliplampApp.Util;
using ControlzEx.Standard;

namespace SuporeSliplampApp.Views
{
    /// <summary>
    /// OpenFileWindow.xaml 的交互逻辑
    /// </summary>
    public partial class OpenFileWindow : Window
    {
        public event EventHandler<ListControlModel> uploadDelegate;
        ResultModel result = new ResultModel();
        public OpenFileWindow()
        {
            InitializeComponent();
            this.DataContext = new PicInputViewModel();
        }

        private void imageBtn_Click(object sender, RoutedEventArgs e)
        {

        }

        private void InputBtn_Click(object sender, RoutedEventArgs e)
        {
            PickPic();
        }
        string fileName = null;
        private void PickPic()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图片|*.jpg;*.jpeg;*.bmp;*.png;*.mp4";
            if (true == openFileDialog.ShowDialog())
            {
                fileName = openFileDialog.FileName;
                //PicInputViewModel.picmodel.PicList.Add(new Model() { Path = file, Name = Util.util.getPicName(file) });
                PicInputViewModel.picmodel.Path = fileName;
                PicInputViewModel.picmodel.Name = Util.util.getPicName(fileName);
                this.pickName.Visibility = Visibility.Visible;
                this.repicBtn.Visibility = Visibility.Visible;
                this.InputBtn.Visibility = Visibility.Collapsed;

            }
        }

        private void cancelBtn_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void confirmBtn_Click(object sender, RoutedEventArgs e)
        {
            var uid = Guid.NewGuid().ToString();
            var newName = uid + ".jpg";
            var model = new ListControlModel();
            
            //CameraViewModel.camModel.VM_Model.Add(new Model() { Path = fileName, Name = Util.util.getPicName(fileName) });
            ScrollControl scrollControl = new ScrollControl();
            ListControlModel listControlModel = new ListControlModel();
            Common.savePic(fileName,newName);
            model.ImageName = newName;
            model.Name = util.getPicName(fileName);
            model.ImgPath = fileName;
            
            this.Close();
            uploadDelegate?.Invoke(this,model);
        }
    }
}
